// C_RTPTIME.cpp: implementation of the C_RTPTIME class.
//
//////////////////////////////////////////////////////////////////////

#include "C_RTPTIME.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

C_RTPTIME::C_RTPTIME()
{

}

C_RTPTIME::~C_RTPTIME()
{

}

unsigned __int64 C_RTPTIME::GetCurrentTime()
{
	static int inited = 0;
	static unsigned __int64 microseconds, initmicroseconds;
	static LARGE_INTEGER time_fre;

	unsigned __int64  emulate_microseconds, microdiff;
	SYSTEMTIME systemtime;
	FILETIME filetime;

	LARGE_INTEGER performancecount;

	QueryPerformanceCounter(&performancecount);
    
	if(!inited){
		inited = 1;
		QueryPerformanceFrequency(&time_fre);
		GetSystemTime(&systemtime);
		SystemTimeToFileTime(&systemtime,&filetime);
		microseconds = ( ((ULONGLONG)(filetime.dwHighDateTime) << 32) + (ULONGLONG)(filetime.dwLowDateTime) ) / 10ui64;
		microseconds-= 11644473600000000ui64; // EPOCH
		initmicroseconds = CalculateMicroseconds(performancecount.QuadPart, time_fre.QuadPart);
	}
    
	emulate_microseconds = CalculateMicroseconds(performancecount.QuadPart, time_fre.QuadPart);

	microdiff = emulate_microseconds - initmicroseconds;

	return microseconds+microdiff;
}

unsigned __int64 C_RTPTIME::CalculateMicroseconds(unsigned __int64 performancecount, unsigned __int64 performancefrequency)
{
	return 1;
}
